package com.koron.device.controller;

import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.device.bean.po.EquipmentCode;
import com.koron.device.service.EquipmentCodeService;
import io.swagger.annotations.Api;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/equipment/code")
@Api(value = "设备编码接口")
public class EquipmentCodeController {


    @Autowired
    private EquipmentCodeService equipmentCodeService;


    private String getCurrDs(){
        return ThreadLocalContext.get().getCurrDs();
    }

    @PostMapping("/save")
    public Response saveEquipmentCode(@RequestBody List<EquipmentCode> equipmentCodes) {
        return Response.success(ADOConnection.runTask(getCurrDs(), equipmentCodeService, "save", Boolean.class, equipmentCodes));
    }

    @GetMapping("/get")
    public Response getEquipmentCodes(@RequestParam String equipmentId) {
        List<String> codes = ADOConnection.runTask(getCurrDs(), equipmentCodeService, "get", List.class, equipmentId);
        return Response.success(codes);
    }

    @GetMapping()
    public Response getEquipmentCodeInfo(@RequestParam String equipmentId) {
        List<EquipmentCode> codes = ADOConnection.runTask(getCurrDs(), equipmentCodeService, "getInfo", List.class, equipmentId);
        return Response.success(codes);
    }
}
